package cn.baage;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import lombok.extern.log4j.Log4j2;

@Log4j2
@Component
public class ExpirationMessageDispatcher {

    @Autowired
    private DataService dataService;

    public void dispatchExpiredKey(String expiredKey) {
        log.info("开始分发过期的 key: {}", expiredKey);
        if (expiredKey.startsWith("queuing:")) {
            handleQueuingKeyExpiration(expiredKey);
        } else if (expiredKey.startsWith("order:")) {
            handleOrderKeyExpiration(expiredKey);
        }
    }

    private void handleQueuingKeyExpiration(String expiredKey) {
        log.info("处理用户相关的过期 key: {}", expiredKey);
        String[] split = expiredKey.split(":");
        dataService.nextData(split[1]);
    }

    private void handleOrderKeyExpiration(String expiredKey) {
        log.info("处理订单相关的过期 key: {}", expiredKey);
        // 实现订单相关的过期 key 处理逻辑
    }
}
